package com.soft.knowledge.service;

import com.soft.knowledge.websocket.WebSocketServer;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WebSocketService {

    @Resource
    WebSocketServer webSocketServer;

    /**
     * 1.要使该注解生效不能和调用该方法的地方在同一个类中
     * 2.登录用户变多该线程会被开启很多，导致异步线程被占满
     * 3.可以引入MQ消息队列去解决
     */
    @Async
    public void sendInfo(String message, String logId){
        MDC.put("LOG_ID", logId);
        webSocketServer.sendInfo(message);
    }
}
